#include "../include/Socket.h"

// 测试套接字创建
void test_socket_creation()
{
    Socket sock;
    assert(sock.CreateSocket());
    std::cout << "✓ Socket creation test passed" << std::endl;
}

// 测试套接字选项设置（地址重用和非阻塞）
void test_socket_options()
{
    Socket sock;
    assert(sock.CreateSocket());
    sock.ReuseAddress(); // 不应崩溃
    sock.NonBlock();     // 不应崩溃
    std::cout << "✓ Socket options test passed" << std::endl;
}

// 测试绑定和监听
void test_bind_and_listen()
{
    Socket sock;
    assert(sock.CreateSocket());
    sock.ReuseAddress();
    // 使用一个较高的端口进行测试，以避免权限问题
    bool bind_success = sock.BindAddress("0.0.0.0", 18888);
    assert(bind_success);
    if (bind_success)
    {
        assert(sock.Listen());
        std::cout << "✓ Socket bind and listen test passed" << std::endl;
    }
    else
    {
        std::cerr << "✗ Socket bind and listen test failed (maybe port is in use?)" << std::endl;
    }
}

int main()
{
    test_socket_creation();
    test_socket_options();
    test_bind_and_listen();

    std::cout << "\nAll socket tests passed!" << std::endl;

    return 0;
}
